<?php
class Cny_model extends CI_Model
{
    private $ci;
    public function __construct(){
        $this->load->database();
        $this->ci = & get_instance();
    }

    public function getCnyDeposit($data,$limit='all',$orderby=''){
        $this->db->select()->from("cny_deposit")->where($data);
        if($limit!='all'){
             $limit = abs($limit);
             $this->db->limit($limit);
        }
        if($orderby!=''){
            $this->db->order_by($orderby);
        }
        $query =  $this->db->get();
        if($limit==1) return $query->row_array();
        return $query->result_array();
    }

    public function getCnyWithdraw($data,$limit='all',$orderby=''){
        $this->db->select()->from("cny_withdraw")->where($data);
        if($limit!='all'){
             $limit = abs($limit);
             $this->db->limit($limit);
        }
        if($orderby!=''){
            $this->db->order_by($orderby);
        }
        $query =  $this->db->get();
        if($limit==1) return $query->row_array();
        return $query->result_array();
    }

    public function updateWithdraw($array,$where){
        $this->db->where($where);
        $rs = $this->db->update('cny_withdraw', $array);
        return $rs;
    }

	public function updateDeposit($array,$where){
        $this->db->where($where);
        $rs = $this->db->update('cny_deposit', $array);
        return $rs;
    }

    public function getCnyBank($data,$limit='all',$orderby=''){
        $this->db->select()->from("cny_bank")->where($data);
        if($limit!='all'){
             $limit = abs($limit);
             $this->db->limit($limit);
        }
        if($orderby!=''){
            $this->db->order_by($orderby);
        }
        $query =  $this->db->get();
        if($limit==1) return $query->row_array();
        return $query->result_array();
    }


    public function addCnyShare($data){
        $rs = $this->db->insert("cny_share",$data);
        if($rs){
            return $this->db->insert_id();
        }else{
            return false;
        }
    }

    public function getCnyShare($data,$limit='all',$orderby=''){
        $this->db->select()->from("cny_share")->where($data);
        if($limit!='all'){
             $limit = abs($limit);
             $this->db->limit($limit);
        }
        if($orderby!=''){
            $this->db->order_by($orderby);
        }
        $query =  $this->db->get();
        if($limit==1) return $query->row_array();
        return $query->result_array();
    }

    public function updateCnyShare($array,$where){
        $this->db->where($where);
        $rs = $this->db->update('cny_share', $array);
        return $rs;
    }

}